<template>
  <a-drawer
    :width="drawerWidth"
    @close="handleCancel"
    :visible="visible"
    :confirmLoading="confirmLoading"
  >
    <template  slot="title">
      <div style="width: 100%;">
        <span>{{ title }}</span>
        <span style="display:inline-block;width:calc(100% - 80px);padding-right:10px;text-align: right">
          <a-button @click="toggleScreen" icon="appstore" style="height:20px;width:20px;border:0px"></a-button>
        </span>
      </div>
    </template>

    <a-spin :spinning="confirmLoading" class="drawer-content">
      <!-- 实体类基本信息 -->
      <a-row align="middle" type="flex">
        <a-form :form="form" layout="inline">
            <a-form-item label="类描述" >
              <a-input autocomplete="off" v-model="model.comment" ></a-input>
            </a-form-item>
            <a-form-item label="类全限定名">
              <a-input autocomplete="off" v-model="model.className" ></a-input>
            </a-form-item>
          <a-form-item label="数据库表名">
            <a-input autocomplete="off" v-model="model.tableName" ></a-input>
          </a-form-item>
          <a-form-item label="基础url">
            <a-input autocomplete="off" v-model="model.urlPrefix" ></a-input>
          </a-form-item>
          <a-form-item label="实现接口">
            <a-select :value="model.interfaceClassNames?model.interfaceClassNames.split(','):[]"
                      mode="multiple"
                      style="width: 500px"
                      @change="interfaceClassNamesChange">
              <a-select-option  value="cn.jtfadmin.base.lang.common.domain.entity.BuildInAbleEntity">
                BuildInAbleEntity
              </a-select-option>
              <a-select-option  value="cn.jtfadmin.base.lang.common.domain.entity.CreateUserInfoEntity">
                CreateUserInfoEntity
              </a-select-option>
              <a-select-option  value="cn.jtfadmin.base.lang.common.domain.entity.NamedEntity">
                NamedEntity
              </a-select-option>
              <a-select-option  value="cn.jtfadmin.base.lang.common.domain.entity.NamedTreeEntity">
                NamedTreeEntity
              </a-select-option>
              <a-select-option  value="cn.jtfadmin.base.lang.common.domain.entity.TreeEntity">
                TreeEntity
              </a-select-option>
            </a-select>
          </a-form-item>
        </a-form>
      </a-row>
      <a-divider />

      <a-row>
        <!-- 实体类字段表 -->
        <a-col :span="12">
          <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="id"
            :columns="columns"
            :dataSource="model.fields"
            :pagination="false"
            :rowSelection="{selectedRowKeys:[field.id],onChange: onSelectChange, type:'radio'}"
          >
        <span slot="ellipsis" slot-scope="text">
          <ak-ellipsis :value="text"/>
        </span>
          </a-table>
        </a-col>
        <a-col :span="1"></a-col>
        <!-- 实体类配置信息 -->
        <a-col :span="8">
          <a-button type="primary" @click="addField">新增字段</a-button>
          <a-button type="primary" @click="delField" style="margin-left: 8px;" v-if="!!field.id && !disDelFields.has(field.name)">删除字段</a-button>
          <a-button type="primary" @click="upField" style="margin-left: 8px;" v-if="!!field.id">上移字段</a-button>
          <a-button type="primary" @click="nextField" style="margin-left: 8px;" v-if="!!field.id">下移字段</a-button>
          <a-tabs default-active-key="base" >
            <a-tab-pane key="base" tab="基础信息">
              <a-form>
                <a-form-item label="名称" >
                  <a-input autocomplete="off" v-model="field.name" ></a-input>
                </a-form-item>
                <a-form-item label="描述" >
                  <a-input autocomplete="off" v-model="field.comment" ></a-input>
                </a-form-item>
                <a-form-item label="字段类型">
                  <ak-dict-select-tag dict-code="FieldTypeEnum" v-model="field.fieldType"></ak-dict-select-tag>
                </a-form-item>
                <a-form-item label="输入类型" v-if="!!field.fieldType">
                  <ak-select-tag :defaultFirst="true" :url="`${url.findInputTypeByFieldType}?fieldType=${field.fieldType}`"
                                 v-model="field.inputType"></ak-select-tag>
                </a-form-item>
                <a-form-item label="字段类型全限定名" v-if="!!field.inputType">
                  <ak-select-tag  :defaultFirst="true"
                                 :url="`${url.findFieldClassByFieldType}?fieldType=${field.fieldType}&inputType=${field.inputType}`"
                                  v-model="field.fieldClassName"
                  ></ak-select-tag>
                </a-form-item>
                <a-form-item label="Lob" v-if="field.fieldClassName=='java.lang.String'">
                  <a-switch default-checked v-model="field.lob"/>
                </a-form-item>
              </a-form>
            </a-tab-pane>
            <a-tab-pane key="file" tab="文件信息" v-if="field.inputType=='File'">
              <a-form >
                <a-form-item label="文件类型:" >
                  <ak-dict-select-tag dict-code="FileType"
                                 v-model="field.fileType"></ak-dict-select-tag>
                </a-form-item>
                <a-form-item label="文件目录" >
                  <a-input autocomplete="off" v-model="field.fileDir" ></a-input>
                </a-form-item>
                <a-form-item label="文件描述">
                  <a-input autocomplete="off" v-model="field.fileDescribe" ></a-input>
                </a-form-item>
                <a-form-item label="最大文件数量">
                  <a-input-number style="width: 100%" :min="1" autocomplete="off" v-model="field.fileNum" ></a-input-number>
                </a-form-item>
                <a-form-item label="是否修改文件名" >
                  <a-switch default-checked v-model="field.fileUpdateName"/>
                </a-form-item>
              </a-form>
            </a-tab-pane>
            <a-tab-pane key="collection" tab="集合信息"  v-if="field.fieldType=='COLLECTION'">
              <a-form >
                <a-form-model-item label="集合类型">
                  <a-select  v-model="field.collectionClassName">

                    <a-select-option value="java.util.Set">java.util.Set</a-select-option>
                    <a-select-option value="java.util.List">java.util.List</a-select-option>
                  </a-select>
                </a-form-model-item>
                <a-form-item label="oneToMany" v-if="!field.manyToMany">
                  <a-switch v-model="field.oneToMany"/>
                </a-form-item>
                <a-form-item label="manyToMany" v-if="!field.oneToMany">
                  <a-switch v-model="field.manyToMany"/>
                </a-form-item>
                <a-form-item label="mappedBy" v-if="field.oneToMany">
                  <a-input autocomplete="off" v-model="field.mappedBy" ></a-input>
                </a-form-item>
                <a-form-item label="关联表名" v-if="field.manyToMany">
                  <a-input autocomplete="off" v-model="field.joinTableName" ></a-input>
                </a-form-item>
                <a-form-item label="关联字段名" v-if="field.manyToMany">
                  <a-input autocomplete="off" v-model="field.joinTableJcName" ></a-input>
                </a-form-item>
                <a-form-item label="对方关联字段名" v-if="field.manyToMany">
                  <a-input autocomplete="off" v-model="field.joinTableIjcName" ></a-input>
                </a-form-item>
                <a-form-model-item label="级联">
                  <a-select v-model="field.cascade">
                    <a-select-option value="">---请选择---</a-select-option>
                    <a-select-option value="ALL">ALL</a-select-option>
                    <a-select-option value="PERSIST">PERSIST</a-select-option>
                    <a-select-option value="MERGE">MERGE</a-select-option>
                    <a-select-option value="REMOVE">REMOVE</a-select-option>
                    <a-select-option value="REFRESH">REFRESH</a-select-option>
                    <a-select-option value="DETACH">DETACH</a-select-option>
                  </a-select>
                </a-form-model-item>
                <a-form-model-item label="加载">
                  <a-select v-model="field.fetch">
                    <a-select-option value="">---请选择---</a-select-option>
                    <a-select-option value="LAZY">LAZY</a-select-option>
                    <a-select-option value="EAGER">EAGER</a-select-option>
                  </a-select>
                </a-form-model-item>
              </a-form>
            </a-tab-pane>
            <a-tab-pane key="entity" tab="实体信息"  v-if="field.fieldType=='ENTITY'">
              <a-form>
                <a-form-item label="oneToOne" v-if="!field.manyToOne">
                  <a-switch v-model="field.oneToOne"/>
                </a-form-item>
                <a-form-item label="manyToOne" v-if="!field.oneToOne">
                  <a-switch v-model="field.manyToOne"/>
                </a-form-item>
                <a-form-item label="mappedBy" v-if="field.oneToOne&&!field.joinColumnName">
                  <a-input autocomplete="off" v-model="field.mappedBy" ></a-input>
                </a-form-item>
                <a-form-item label="关联字段名" v-if="field.manyToOne || (field.oneToOne&&!field.mappedBy)">
                  <a-input autocomplete="off" v-model="field.joinColumnName" ></a-input>
                </a-form-item>
                <a-form-model-item label="级联">
                  <a-select v-model="field.cascade">
                    <a-select-option value="">---请选择---</a-select-option>
                    <a-select-option value="ALL">ALL</a-select-option>
                    <a-select-option value="PERSIST">PERSIST</a-select-option>
                    <a-select-option value="MERGE">MERGE</a-select-option>
                    <a-select-option value="REMOVE">REMOVE</a-select-option>
                    <a-select-option value="REFRESH">REFRESH</a-select-option>
                    <a-select-option value="DETACH">DETACH</a-select-option>
                  </a-select>
                </a-form-model-item>
                <a-form-model-item label="加载">
                  <a-select v-model="field.fetch">
                    <a-select-option value="">---请选择---</a-select-option>
                    <a-select-option value="LAZY">LAZY</a-select-option>
                    <a-select-option value="EAGER">EAGER</a-select-option>
                  </a-select>
                </a-form-model-item>
              </a-form>
            </a-tab-pane>
            <a-tab-pane key="valid" tab="验证信息">
              <a-form >
                <a-form-item label="必须" >
                  <a-switch style="width: 50%" v-model="field.required"/>
                </a-form-item>
                <a-form-item label="唯一" v-if="field.fieldType=='BASIC'">
                  <a-switch style="width: 50%" v-model="field.unique"/>
                </a-form-item>
                <a-form-item label="最大" v-if="field.fieldClassName=='java.lang.Integer'
                || field.fieldClassName=='java.lang.Long'|| field.fieldClassName=='java.math.BigInteger'">
                  <a-input-number style="width: 100%" autocomplete="off" v-model="field.max" ></a-input-number>
                </a-form-item>
                <a-form-item label="最小" v-if="field.fieldClassName=='java.lang.Integer'
                || field.fieldClassName=='java.lang.Long'|| field.fieldClassName=='java.math.BigInteger'">
                  <a-input-number style="width: 100%" autocomplete="off" v-model="field.min" ></a-input-number>
                </a-form-item>
                <a-form-item label="最大" v-if="field.fieldClassName=='java.math.BigDecimal'">
                  <a-input-number style="width: 100%" :step="0.00000001" autocomplete="off" v-model="field.max" ></a-input-number>
                </a-form-item>
                <a-form-item label="最小" v-if="field.fieldClassName=='java.math.BigDecimal'">
                  <a-input-number style="width: 100%" :step="0.00000001" autocomplete="off" v-model="field.min" ></a-input-number>
                </a-form-item>
                <a-form-item label="长度最长" v-if="field.fieldClassName=='java.lang.String'">
                  <a-input-number style="width: 100%" autocomplete="off" v-model="field.max" ></a-input-number>
                </a-form-item>
                <a-form-item label="长度最短" v-if="field.fieldClassName=='java.lang.String'">
                  <a-input-number style="width: 100%" autocomplete="off" v-model="field.min" ></a-input-number>
                </a-form-item>
              </a-form>
            </a-tab-pane>
            <a-tab-pane key="actions" tab="功能信息">
              <a-form >
                <a-form-item label="新增" >
                  <a-switch style="width: 50%" v-model="field.addItem"/>
                </a-form-item>
                <a-form-item label="编辑" >
                  <a-switch style="width: 50%" v-model="field.editItem"/>
                </a-form-item>
                <a-form-item label="model" v-if="(field.fieldType=='ENTITY' || field.fieldType=='COLLECTION') &&!!field.fieldClassName">
                  <ak-select-multiple-tag :url="`${url.findFieldsByEntityClass}?entity=${field.fieldClassName}`" v-model="field.modelEmbed"></ak-select-multiple-tag>
                </a-form-item>
                <a-form-item label="model" v-else>
                  <a-switch style="width: 50%" v-model="field.modelItem"/>
                </a-form-item>
                <a-form-item label="列表" v-if="(field.fieldType=='ENTITY' || field.fieldType=='COLLECTION') &&!!field.fieldClassName">
                  <ak-select-multiple-tag :url="`${url.findFieldsByEntityClass}?entity=${field.fieldClassName}`" v-model="field.listEmbed"></ak-select-multiple-tag>
                </a-form-item>
                <a-form-item label="列表" v-else>
                  <a-switch style="width: 50%" v-model="field.listItem"/>
                </a-form-item>

                <a-form-item label="导入导出" v-if="(field.fieldType=='ENTITY' || field.fieldType=='COLLECTION') &&!!field.fieldClassName">
                  <ak-select-multiple-tag :url="`${url.findFieldsByEntityClass}?entity=${field.fieldClassName}`" v-model="field.excelEmbed"></ak-select-multiple-tag>
                </a-form-item>
                <a-form-item label="导入导出" v-else>
                  <a-switch style="width: 50%" v-model="field.excelItem"/>
                </a-form-item>

                <a-form-item label="导入导出标识" v-if="(field.fieldType=='ENTITY' || field.fieldType=='COLLECTION') &&!!field.fieldClassName">
                  <ak-select-tag :url="`${url.findFieldsByEntityClass}?entity=${field.fieldClassName}`" v-model="field.excelEmbedId"></ak-select-tag>
                </a-form-item>
                <a-form-item label="导入导出标识" v-else >
                  <a-switch style="width: 50%" v-model="field.excelId"/>
                </a-form-item>
                <a-form-item label="查询" v-if="(field.fieldType=='ENTITY' || field.fieldType=='COLLECTION') &&!!field.fieldClassName">
                  <ak-select-multiple-tag :url="`${url.findFieldsByEntityClass}?entity=${field.fieldClassName}`" v-model="field.selectEmbed"></ak-select-multiple-tag>
                </a-form-item>
                <a-form-item label="查询" v-else>
                  <a-switch style="width: 50%" v-model="field.selectItem"/>
                </a-form-item>
                <a-form-item label="新增编辑显示" v-if="(field.fieldType=='ENTITY' || field.fieldType=='COLLECTION') &&!!field.fieldClassName">
                  <ak-select-multiple-tag :url="`${url.findFieldsByEntityClass}?entity=${field.fieldClassName}`" v-model="field.showColumnName"></ak-select-multiple-tag>
                </a-form-item>

              </a-form>
            </a-tab-pane>
          </a-tabs>

        </a-col>
      </a-row>

    </a-spin>


    <div class="drawer-bootom-button" v-show="!disableSubmit">
      <a-popconfirm title="确定放弃编辑？" @confirm="handleCancel" okText="确定" cancelText="取消">
        <a-button style="margin-right: .8rem">取消</a-button>
      </a-popconfirm>
      <a-button @click="handleSubmit" type="primary" :loading="confirmLoading">提交</a-button>
    </div>
  </a-drawer>
</template>

<script>
  import AkfhModelDrawMixin from "../../../mixin/AkfhModelDrawMixin";
  import ARow from "ant-design-vue/es/grid/Row";
  import ACol from "ant-design-vue/es/grid/Col";
  import {codeGenClassUrl} from '../../../api/url'
  import AkEllipsis from '../../../components/akfh/AkEllipsis'
  import AkDictSelectTag from "../../../components/akfh/AkDictSelectTag";
  import AkDictSelectMultipleTag from '../../../components/akfh/AkDictSelectMultipleTag'
  import AkSelectMultipleTag from '../../../components/akfh/AkSelectMultipleTag'
  import { randomUUID } from '../../../utils/util'
  import AkSelectTag from '../../../components/akfh/AkSelectTag'
  import AFormModelItem from 'ant-design-vue/es/form-model/FormItem'
    export default {
      name: "CodeGenClassModal",
      components: { AFormModelItem, AkSelectTag, AkSelectMultipleTag, AkDictSelectMultipleTag, AkDictSelectTag, ACol, ARow, AkEllipsis},
      mixins:[AkfhModelDrawMixin],
      data(){
        return {
          columns:[
            {
              title: '字段名',
              dataIndex: 'name',
              scopedSlots: { customRender: 'ellipsis' },
            }, {
              title: '描述',
              dataIndex: 'comment',
              scopedSlots: { customRender: 'ellipsis' },

            },{
              title: '类型',
              dataIndex: 'fieldClassName',
              scopedSlots: { customRender: 'ellipsis' },
            },

          ],
          field:{
            id:'',
            inputType:'',
            fieldType:'',
            fieldClass:'',
            oneToMany:false,
            manyToMany:false,
            manyToOne:false,
            oneToOne:false,
            cascade:'',
            fetch:'',
            mappedBy:'',
            joinTableName:'',
            joinTableJcName:'',
            joinTableIjcName:'',
            joinColumnName:'',

            min:0,
            max:99999999,
            required:false,
            lob:false,
            unique:false,

            editItem:false,
            listItem:false,
            addItem:false,
            modelItem:false,
            excelItem:false,
            selectItem:false,
            excelId:false,
          },
          disDelFields:new Set(['id', 'createDateTime', 'updateDateTime','createUserId','updateUserId']),
          url:codeGenClassUrl
        }
      },
      methods:{
        add (param) {
          this.edit(param||{
            superClassName:'cn.jtfadmin.base.data.jpa.domain.entity.BaseEntity',
            fields:[
              {
                id:randomUUID(),
                name:'id',
                fieldClassName:'java.lang.String',
                comment:'id',
                fieldType:'BASIC',
                fieldType_dictText:'基础类型',
                inputType:'TEXT',
                inputType_dictText:'文本框',

              },
              {
                id:randomUUID(),
                name:'createDateTime',
                fieldClassName:'java.time.LocalDateTime',
                comment:'创建时间',
                fieldType:'BASIC',
                fieldType_dictText:'基础类型',
                inputType:'DATE_TIME',
                inputType_dictText:'日期时间'

              },
              {
                id:randomUUID(),
                name:'updateDateTime',
                fieldClassName:'java.time.LocalDateTime',
                comment:'更新时间',
                fieldType:'BASIC',
                fieldType_dictText:'基础类型',
                inputType:'DATE_TIME',
                inputType_dictText:'日期时间'

              },
              {
                id:randomUUID(),
                name:'createUserId',
                fieldClassName:'java.lang.String',
                comment:'创建人id',
                fieldType:'BASIC',
                fieldType_dictText:'基础类型',
                inputType:'TEXT',
                inputType_dictText:'文本框'

              },
              {
                id:randomUUID(),
                name:'updateUserId',
                fieldClassName:'java.lang.String',
                comment:'更新人id',
                fieldType:'BASIC',
                fieldType_dictText:'基础类型',
                inputType:'TEXT',
                inputType_dictText:'文本框'

              },
            ]
          });
        },
        interfaceClassNamesChange(v){
          this.model.interfaceClassNames = v.join(',');

          let names = new Set(v);
          if(names.has('cn.jtfadmin.base.lang.common.domain.entity.BuildInAbleEntity')){
            if(this.model.fields.filter(t=>t.name=='buildInAble').length == 0){
              this.model.fields.push(
              {
                id:randomUUID(),
                name:'buildInAble',
                fieldClassName:'cn.jtfadmin.base.lang.enums.BooleanEnum',
                comment:'内置数据',
                fieldType:'ENUM',
                fieldType_dictText:'枚举',
                inputType:'RADIO',
                inputType_dictText:'单选'
              })
            }
          }else {
            this.model.fields = this.model.fields.filter(t=>t.name!='buildInAble');
          }
          if(names.has('cn.jtfadmin.base.lang.common.domain.entity.CreateUserInfoEntity')){
            if(this.model.fields.filter(t=>t.name=='createUsername').length == 0){
              this.model.fields.push(
                {
                  id:randomUUID(),
                  name:'createUsername',
                  fieldClassName:'java.lang.String',
                  comment:'创建人账号',
                  fieldType:'BASIC',
                  fieldType_dictText:'基础类型',
                  inputType:'TEXT',
                  inputType_dictText:'文本框'
                })
            }
            if(this.model.fields.filter(t=>t.name=='createUserRealname').length == 0){
              this.model.fields.push(
                {
                  id:randomUUID(),
                  name:'createUserRealname',
                  fieldClassName:'java.lang.String',
                  comment:'创建人真实姓名',
                  fieldType:'BASIC',
                  fieldType_dictText:'基础类型',
                  inputType:'TEXT',
                  inputType_dictText:'文本框'
                })
            }
          }else {
            this.model.fields = this.model.fields.filter(t=>t.name!='createUsername' && t.name!='createUserRealname');
          }
          if(names.has('cn.jtfadmin.base.lang.common.domain.entity.NamedEntity')
          ||names.has('cn.jtfadmin.base.lang.common.domain.entity.NamedTreeEntity')){
            if(this.model.fields.filter(t=>t.name=='name').length == 0){
              this.model.fields.push(
                {
                  id:randomUUID(),
                  name:'name',
                  fieldClassName:'java.lang.String',
                  comment:'名称',
                  fieldType:'BASIC',
                  fieldType_dictText:'基础类型',
                  inputType:'TEXT',
                  inputType_dictText:'文本框'
                })
            }
          }else {
            this.model.fields = this.model.fields.filter(t=>t.name!='name');
          }
          if(names.has('cn.jtfadmin.base.lang.common.domain.entity.TreeEntity')
            ||names.has('cn.jtfadmin.base.lang.common.domain.entity.NamedTreeEntity')){
            if(this.model.fields.filter(t=>t.name=='parentId').length == 0){
              this.model.fields.push(
                {
                  id:randomUUID(),
                  name:'parentId',
                  fieldClassName:'java.lang.String',
                  comment:'父id',
                  fieldType:'BASIC',
                  fieldType_dictText:'基础类型',
                  inputType:'TEXT',
                  inputType_dictText:'文本框'
                })
            }
            if(this.model.fields.filter(t=>t.name=='parentIds').length == 0){
              this.model.fields.push(
                {
                  id:randomUUID(),
                  name:'parentIds',
                  fieldClassName:'java.lang.String',
                  comment:'父ids',
                  fieldType:'BASIC',
                  fieldType_dictText:'基础类型',
                  inputType:'TEXT',
                  inputType_dictText:'文本框'
                })
            }
          }else {
            this.model.fields = this.model.fields.filter(t=>t.name!='parentId'&& t.name!='parentIds');
          }
          this.model = Object.assign({},this.model);
        },
        // 根据屏幕变化,设置抽屉尺寸
        resetScreenSize(){
          let screenWidth = document.body.clientWidth;
          this.drawerWidth = screenWidth;

        },
        onSelectChange(vid, v){
          console.log(vid, v)
          this.field = v[0];
        },
        addField(){
          this.model.fields = this.model.fields||[];
          let field ={id:randomUUID()};
          this.model.fields.push(field);
          this.model = Object.assign({},this.model);
          this.field=field;
        },
        delField(){
          this.model.fields = this.model.fields.filter(t=>t!=this.field);
        },
        nextField(){
          let temp = [];
          let j = null;
          for (let i = 0; i < this.model.fields.length; i++) {
            let f = this.model.fields[i];
            if(f==this.field){

              j=i;
            }
            if(j==null){
              temp.push(f);
              continue;
            }
            if(j===i&&j+1===this.model.fields.length){
              temp.push(f);
              continue;
            }else if(j===i){
              temp.push(this.model.fields[i+1]);
              temp.push(f);
              continue;
            }else if(j+1===i){
              continue;
            }
            temp.push(f);


          };
          this.model.fields = temp;
          this.model = Object.assign({}, this.model);


        },
        upField(){
          let temp = [];
          let j = null;
          for (let i = 0; i < this.model.fields.length; i++) {
            let f = this.model.fields[i];
            if(f==this.field){
              j=i;
            }
            if(j==i&&j==0){
              temp.push(f);
              continue;
            }else if(j==i){
              temp[j]=temp[j-1];
              temp[j-1]=f;
              continue;
            }
            temp.push(f);
          };
          this.model.fields = temp;
          this.model = Object.assign({}, this.model);
        },
        beforeHandleSubmit(formData){
          if(!formData.className){
            this.$message.warn("类全限定名不能为空")
            return false;
          }
          if(!formData.tableName){
            this.$message.warn("数据库表名不能为空")
            return false;
          }
          if(!formData.comment){
            this.$message.warn("类描述不能为空")
            return false;
          }
          if(!formData.urlPrefix){
            this.$message.warn("基础url不能为空")
            return false;
          }
          for (let i = 0; i < formData.fields.length; i++) {
            let field = formData.fields[i];
            if(!field.name){
              this.$message.warn("字段名称不能为空")
              return false;
            }
            if(!field.comment){
              this.$message.warn("字段:"+field.name+" 描述名称不能为空")
              return false;
            }
            if(!field.fieldType){
              this.$message.warn("字段:"+field.name+" 字段类型不能为空")
              return false;
            }
            if(!field.inputType){
              this.$message.warn("字段:"+field.name+" 输入类型不能为空")
              return false;
            }
            if(!field.fieldClassName){
              this.$message.warn("字段:"+field.name+" 字段类型全限定名不能为空")
              return false;
            }
            if(field.fieldType=='ENTITY'){
              if(!field.oneToOne && !field.manyToOne){
                this.$message.warn("字段:"+field.name+" 实体信息关联类型未设置")
                return false;
              }
              if(field.manyToOne){
                if(!field.joinColumnName){
                  this.$message.warn("字段:"+field.name+" 实体信息关联字段未设置")
                  return false;
                }
              }
              if(field.oneToOne){
                if(!field.joinColumnName && !field.mappedBy){mappedBy
                  console.log(field)
                  this.$message.warn("字段:"+field.name+" 实体信息关联字段或mappedBy未设置")
                  return false;
                }
              }
            }
            if(field.fieldType=='COLLECTION'){
              if(!field.collectionClassName){
                this.$message.warn("字段:"+field.name+" 集合信息集合类型未设置")
                return false;
              }
              if(!field.manyToMany && !field.oneToMany){
                this.$message.warn("字段:"+field.name+" 集合信息关联类型未设置")
                return false;
              }
              if(field.oneToMany){
                if(!field.mappedBy){
                  this.$message.warn("字段:"+field.name+" 集合信息mappedBy未设置")
                  return false;
                }
              }
              if(field.manyToMany){
                if(!field.joinTableName){
                  this.$message.warn("字段:"+field.name+" 集合信息关联表名未设置")
                  return false;
                }
                if(!field.joinTableIjcName){
                  this.$message.warn("字段:"+field.name+" 集合信息对方关联字段名未设置")
                  return false;
                }
                if(!field.joinTableJcName){
                  this.$message.warn("字段:"+field.name+" 集合信息关联字段名未设置")
                  return false;
                }
              }
            }
          }
          return true;
        }
      }
    }
</script>

<style scoped>
  .drawer-bootom-button {
    position: absolute;
    bottom: 0;
    width: 100%;
    border-top: 1px solid #e8e8e8;
    padding: 20px 16px;
    text-align: right;
    left: 0;
    background: #fff;
    border-radius: 0 0 2px 2px;
  }
</style>